<template name="home">
  <view class>
    <!-- <view
            class="getpassbtn2"
            @click="toOpenDoor"
          >
            <view class="btn">蓝牙开门</view>
          </view> -->
    <web-view
      :webview-styles="webviewStyles"
      :src="order.openKey"
      v-if="http == 'http'"
    ></web-view>
    <img src="/static/img/bg.png" alt class="hubg" />
    <scroll-view
      scroll-y
      style="height: 100%"
      class="home"
      v-if="http != 'http'"
    >
      <view class="toppart" v-if="http == 'wu' || http == 'mima'">
        <view class="none" v-if="http == 'wu'">
          <view v-if="zanwuopen == false">
            <image src="../../static/img/none.png" mode class="noneimg" />
            <view class="mei">您暂无密码或已失效</view>
            <view class="zixun" @click="call">如有疑问请联系客服</view>
          </view>
          <view v-if="zanwuopen == true">
            <view class="zwsfz" style="margin-top: -80px">
              <image
                src="http://m.cloudhouse.live/%E6%88%BF%E5%AE%A2%E2%80%94%E6%97%A0%E6%B3%95%E5%BC%80%E9%97%A8%E6%8F%90%E7%A4%BA%E5%9B%BE.png"
                mode
                class="sfzimg"
              />
              <view class="zanwutext">
                <view class="zanwutitle"
                  >入住时间为当日<text style="color: #ff3333"
                    >{{ hour }}:{{ minutes }}</text
                  ></view
                >
                <view class="zanwutime">未到订单入住时间暂无法开门</view>
              </view>
            </view>
          </view>
        </view>
        <view class v-if="http == 'mima'">
          <view class="title">
            请输入智能锁密码
            <view class>按#键开门</view>
          </view>

          <view class="key">
            <view v-for="(item, k) in key" :key="k">{{ item }}</view>
          </view>
          <view class="qiun-columns" style="margin-top: 20rpx">
            <view class="qiun-charts3">
              <canvas
                canvas-id="canvasArcbar1"
                id="canvasArcbar1"
                class="charts3"
              ></canvas>
            </view>
            <view class="time">剩余时间:{{ time }}</view>
          </view>
        </view>
      </view>
      <view class v-if="http == 'jianpai'">
        <view class="toppart" v-if="zanwuopen == false">
          <view class="sfz">
            <image src="../../static/img/wxts.png" mode class="sfzimg" />
          </view>
          <view class>
            <view class="sfztitle">开门方式</view>
            <view class="english">Open the door way</view>
            <view class="by">首次开门必须将身份证紧贴门锁5秒</view>
            <view class="by">验证成功后按压门把手开门</view>
            <view class="tip">
              (再次进入房间可按“999
              <image
                src="../../static/img/dh.png"
                mode
                class="dh"
              />”人脸识别开门)
            </view>

            <view class="qiun-columns">
              <view class="qiun-charts3">
                <canvas
                  canvas-id="canvasArcbar1"
                  id="canvasArcbar1"
                  class="charts3"
                ></canvas>
              </view>
              <view class="time">剩余时间:{{ time }}</view>
            </view>
          </view>
        </view>
        <!-- //zanwuopen -->
        <view class="toppart" v-if="zanwuopen == true">
          <view class="zwsfz">
            <image
              src="http://m.cloudhouse.live/%E6%88%BF%E5%AE%A2%E2%80%94%E6%97%A0%E6%B3%95%E5%BC%80%E9%97%A8%E6%8F%90%E7%A4%BA%E5%9B%BE.png"
              mode
              class="sfzimg"
            />
            <view class="zanwutext">
              <view class="zanwutitle"
                >入住时间为当日<text style="color: #ff3333"
                  >{{ hour }}:{{ minutes }}</text
                ></view
              >
              <view class="zanwutime">未到订单入住时间暂无法开门</view>
            </view>
          </view>
          <view class>
            <view class="zanwusfztitle">开门方式</view>
            <view class="english">Open the door way</view>
            <view class="zanwuby">首次开门必须将身份证紧贴门锁5秒</view>
            <view class="zanwuby">验证成功后按压门把手开门</view>
            <view class="zanwutip">
              (再次进入房间可按“999
              <image
                src="../../static/img/dh.png"
                mode
                class="dh"
              />”人脸识别开门)
            </view>
          </view>
        </view>
      </view>
      <!-- 蓝牙 -->
      <view v-if="http == 'bluetooth'">
        <view
          class="toppart"
          v-if="zanwuopen == true"
          style="padding-bottom: 40upx"
        >
          <view class="zwsfz">
            <image
              src="http://m.cloudhouse.live/%E6%88%BF%E5%AE%A2%E2%80%94%E6%97%A0%E6%B3%95%E5%BC%80%E9%97%A8%E6%8F%90%E7%A4%BA%E5%9B%BE.png"
              mode
              class="sfzimg"
            />
            <view class="zanwutext">
              <view class="zanwutitle"
                >入住时间为当日<text style="color: #ff3333"
                  >{{ hour }}:{{ minutes }}</text
                ></view
              >
              <view class="zanwutime">未到订单入住时间暂无法开门</view>
            </view>
          </view>
          <view class>
            <view class="zanwusfztitle">开门方式</view>
            <view class="english">Open the door way</view>

            <view class="zanwuby"
              >触亮门锁正对屏幕识别框 人脸识别成功按压门把手开门</view
            >
            <!-- <view class="zanwuby">验证成功后按压门把手开门</view> -->
            <!-- 	<view class="zanwutip">(再次进入房间可按“999
							<image
								src="../../static/img/dh.png"
								mode=""
								class="dh"
							></image>
            ”人脸识别开门)</view>-->
          </view>
        </view>
        <view class="toppart" v-if="zanwuopen == false">
          <view class="sfztitle">开门方式</view>
          <view class="english">Open the door way</view>
          <view class="wusfz">
            <image
              src="http://m.cloudhouse.live/V4%E9%97%A8%E9%94%81%E5%BC%80%E9%97%A8%E6%8F%90%E7%A4%BA%E4%BA%8E.png"
              mode="widthFix"
              style="width: 50%"
            />
          </view>
          <view class>
            <view class="qiun-columns" style="margin-top: 20rpx">
              <view class="time">剩余时间:{{ time }}</view>
            </view>
          </view>
        </view>
        <view
          class="getpassbtn"
          v-if="pwdSwitchStatus == 1 && zanwuopen == false"
          @click="bluetoothopen"
        >
          <view class="btn">蓝牙开门</view>
        </view>
      </view>
      <!-- kejixia -->
      <view v-if="http == 'kejixia'">
        <view
          class="toppart"
          v-if="zanwuopen == true"
          style="padding-bottom: 40upx"
        >
          <view class="zwsfz">
            <image
              src="http://m.cloudhouse.live/%E6%88%BF%E5%AE%A2%E2%80%94%E6%97%A0%E6%B3%95%E5%BC%80%E9%97%A8%E6%8F%90%E7%A4%BA%E5%9B%BE.png"
              mode
              class="sfzimg"
            />
            <view class="zanwutext">
              <view class="zanwutitle"
                >入住时间为当日<text style="color: #ff3333"
                  >{{ hour }}:{{ minutes }}</text
                ></view
              >
              <view class="zanwutime">未到订单入住时间暂无法开门</view>
            </view>
          </view>
          <view class>
            <view class="zanwusfztitle">开门方式</view>
            <view class="english">Open the door way</view>

            <view class="zanwuby">请通过蓝牙或输入密码开门</view>
          </view>
        </view>
        <view class="toppart" v-if="zanwuopen == false">
          <view class="sfztitle">开门方式</view>
          <view class="english">Open the door way</view>
          <view class="wusfz">
            <image
              src="http://m.cloudhouse.live/%E7%A7%91%E6%8A%80%E4%BE%A0-%E8%93%9D%E7%89%99.png"
              mode="widthFix"
              style="width: 40%"
            />
            <image
              src="http://m.cloudhouse.live/%E7%A7%91%E6%8A%80%E4%BE%A0-%E5%AF%86%E7%A0%81.png"
              mode="widthFix"
              style="width: 40%"
            />
          </view>
          <view class>
            <view class="qiun-columns" style="margin-top: 20rpx">
              <view class="time">剩余时间:{{ time }}</view>
            </view>
          </view>
        </view>
        <view class="btnbox">
          <view
            class="getpassbtn2"
            v-if="pwdSwitchStatus == 1 && zanwuopen == false"
            @click="toOpenDoor"
          >
            <view class="btn">蓝牙开门</view>
          </view>
          <!-- <view
            class="getpassbtn2"
            v-if="pwdSwitchStatus == 1 && zanwuopen == false"
            @click="setPassfive"
          >
            <view class="btn">密码开门</view>
          </view> -->
        </view>
      </view>
      <!-- keting -->
      <view v-if="http == 'keting'">
        <view
          class="toppart"
          v-if="zanwuopen == true"
          style="padding-bottom: 40upx"
        >
          <view class="zwsfz">
            <image
              src="http://m.cloudhouse.live/%E6%88%BF%E5%AE%A2%E2%80%94%E6%97%A0%E6%B3%95%E5%BC%80%E9%97%A8%E6%8F%90%E7%A4%BA%E5%9B%BE.png"
              mode
              class="sfzimg"
            />
            <view class="zanwutext">
              <view class="zanwutitle"
                >入住时间为当日<text style="color: #ff3333"
                  >{{ hour }}:{{ minutes }}</text
                ></view
              >
              <view class="zanwutime">未到订单入住时间暂无法开门</view>
            </view>
          </view>
          <view class>
            <view class="zanwusfztitle">开门方式</view>
            <view class="english">Open the door way</view>

            <view class="zanwuby">请通过蓝牙或输入密码开门</view>
          </view>
        </view>
        <view class="toppart" v-if="zanwuopen == false">
          <view class="sfztitle">开门方式</view>
          <view class="english">Open the door way</view>
          <view class="wusfz">
            <image
              src="http://m.cloudhouse.live/%E7%A7%91%E6%8A%80%E4%BE%A0-%E8%93%9D%E7%89%99.png"
              mode="widthFix"
              style="width: 50%"
            />
          </view>
          <view class>
            <view class="qiun-columns" style="margin-top: 20rpx">
              <view class="time">剩余时间:{{ time }}</view>
            </view>
          </view>
        </view>
        <view class="btnbox">
          <view
            class="getpassbtn2"
            v-if="pwdSwitchStatus == 1 && zanwuopen == false"
            @click="toOpenDoorketing"
          >
            <view class="btn">蓝牙开门</view>
          </view>
        </view>
      </view>
      <!-- 箭牌2 -->

      <view class v-if="http == 'jianpai2'">
        <view v-if="zanwuopen == false">
          <view class="toppart">
            <view class="sfztitle">开门方式</view>
            <view class="english">Open the door way</view>
            <view class="sfz">
              <image
                src="http://m.cloudhouse.live/%E5%AE%89%E5%BF%83%E5%AE%BF%E6%88%BF%E5%AE%A2%E2%80%94%E2%80%94%E5%BC%80%E9%97%A8%E6%8F%90%E7%A4%BA"
                mode="widthFix"
                style="width: 100%"
              />
            </view>
            <view class>
              <!-- <view class="by">触亮门锁屏幕，点击人脸框，面部置于框中，进入人脸识别。语音提示成功后，按压门把手开门</view> -->

              <view class="qiun-columns" style="margin-top: 20rpx">
                <!-- <view class="qiun-charts3">
									<canvas
										canvas-id="canvasArcbar1"
										id="canvasArcbar1"
										class="charts3"
									></canvas>
                </view>-->
                <view class="time">剩余时间:{{ time }}</view>
              </view>
            </view>
          </view>
          <view class="getpassbtn" v-if="pwdSwitchStatus == 1" @click="setPass">
            <view class="btn">获取密码</view>
          </view>
        </view>
        <!-- //zanwuopen -->
        <view class="toppart" v-if="zanwuopen == true">
          <view class="zwsfz">
            <image
              src="http://m.cloudhouse.live/%E6%88%BF%E5%AE%A2%E2%80%94%E6%97%A0%E6%B3%95%E5%BC%80%E9%97%A8%E6%8F%90%E7%A4%BA%E5%9B%BE.png"
              mode
              class="sfzimg"
            />
            <view class="zanwutext">
              <view class="zanwutitle"
                >入住时间为当日<text style="color: #ff3333"
                  >{{ hour }}:{{ minutes }}</text
                ></view
              >
              <view class="zanwutime">未到订单入住时间暂无法开门</view>
            </view>
          </view>
          <view class>
            <view class="zanwusfztitle">开门方式</view>
            <view class="english">Open the door way</view>
            <view class="zanwuby"
              >触亮门锁屏幕，点击人脸框，面部置于框中，进入人脸识别。语音提示成功后，按压门把手开门</view
            >
            <!-- <view class="zanwuby">验证成功后按压门把手开门</view> -->
            <!-- <view class="zanwutip">(再次进入房间可按“999
							<image
								src="../../static/img/dh.png"
								mode=""
								class="dh"
							></image>
							”人脸识别开门)</view>
            -->
          </view>
        </view>
      </view>
      <!-- 箭牌3 -->
      <view class v-if="http == 'jianpai3'">
        <view v-if="zanwuopen == false">
          <view class="toppart">
            <view class>
              <view class="sfztitle">开门方式</view>
              <view class="english">Open the door way</view>

              <view class="sfz">
                <image
                  src="http://m.cloudhouse.live/%E5%AE%89%E5%BF%83%E5%AE%BF%E6%88%BF%E5%AE%A2%E2%80%94%E2%80%94%E5%BC%80%E9%97%A8%E6%8F%90%E7%A4%BA"
                  mode="widthFix"
                  style="width: 100%"
                />
              </view>
              <!-- <view class="by">触亮门锁正对屏幕识别框 语音提示识别成功按压门把手开门</view> -->

              <view class="qiun-columns" style="padding-top: 38upx">
                <!-- <view class="qiun-charts3">
									<canvas
										canvas-id="canvasArcbar1"
										id="canvasArcbar1"
										class="charts3"
									></canvas>
                </view>-->
                <view class="time">剩余时间:{{ time }}</view>
              </view>
            </view>
          </view>
          <view
            class="getpassbtn"
            v-if="pwdSwitchStatus == 1"
            @click="getPass(1)"
          >
            <view class="btn">获取密码</view>
          </view>
        </view>
        <!-- //zanwuopen -->
        <view
          class="toppart"
          v-if="zanwuopen == true"
          style="padding-bottom: 40upx"
        >
          <view class="zwsfz">
            <image
              src="http://m.cloudhouse.live/%E6%88%BF%E5%AE%A2%E2%80%94%E6%97%A0%E6%B3%95%E5%BC%80%E9%97%A8%E6%8F%90%E7%A4%BA%E5%9B%BE.png"
              mode
              class="sfzimg"
            />
            <view class="zanwutext">
              <view class="zanwutitle"
                >入住时间为当日<text style="color: #ff3333"
                  >{{ hour }}:{{ minutes }}</text
                ></view
              >
              <view class="zanwutime">未到订单入住时间暂无法开门</view>
            </view>
          </view>
          <view class>
            <view class="zanwusfztitle">开门方式</view>
            <view class="english">Open the door way</view>
            <view v-if="http == 'bluetooth'"> wwe </view>

            <view class="zanwuby" v-else
              >触亮门锁正对屏幕识别框 语音提示识别成功按压门把手开门</view
            >
            <!-- <view class="zanwuby">验证成功后按压门把手开门</view> -->
            <!-- 	<view class="zanwutip">(再次进入房间可按“999
							<image
								src="../../static/img/dh.png"
								mode=""
								class="dh"
							></image>
            ”人脸识别开门)</view>-->
          </view>
        </view>
      </view>
      <!-- ax6 -->
      <view v-if="http == 'ax6'">
        <view
          class="toppart"
          v-if="zanwuopen == true"
          style="padding-bottom: 40upx"
        >
          <view class="zwsfz">
            <image
              src="http://m.cloudhouse.live/%E6%88%BF%E5%AE%A2%E2%80%94%E6%97%A0%E6%B3%95%E5%BC%80%E9%97%A8%E6%8F%90%E7%A4%BA%E5%9B%BE.png"
              mode
              class="sfzimg"
            />
            <view class="zanwutext">
              <view class="zanwutitle"
                >入住时间为当日<text style="color: #ff3333"
                  >{{ hour }}:{{ minutes }}</text
                ></view
              >
              <view class="zanwutime">未到订单入住时间暂无法开门</view>
            </view>
          </view>
          <view class>
            <view class="zanwusfztitle">开门方式</view>
            <view class="english">Open the door way</view>

            <view class="zanwuby">请通过蓝牙或输入密码开门</view>
          </view>
        </view>
        <view class="toppart" v-if="zanwuopen == false">
          <view class="sfztitle">开门方式</view>
          <view class="english">Open the door way</view>
          <view class="wusfz">
            <image
              src="https://cloudhouse.mynatapp.cc/anxinsu/app/common/ax6.jpg"
              mode="widthFix"
            />
          </view>
          <view class>
            <view class="qiun-columns" style="margin-top: 20rpx">
              <view class="time">剩余时间:{{ time }}</view>
            </view>
          </view>
        </view>
        <view class="btnbox">
          <view
            class="getpassbtn2"
            v-if="pwdSwitchStatus == 1 && zanwuopen == false"
            @click="bluetoothopenhx"
          >
            <view class="btn">蓝牙开门</view>
          </view>
        </view>
      </view>
      <!-- <view class="bigbg">
        <view class="passtitle">查看密码</view>
        <view class="passtip">请在时效内将二维码对准门锁识别开门</view>
        <view class="passtip">时效为5分钟单次二维码仅可使用一次</view>
      </view>-->
      <view class="bigbg">
        <view class="passtitle">查看密码</view>
        <view class="passPop passPoptwo">
          <p class="title">密码设置</p>
          <view class="tshi" style="padding-top: 60upx">
            <image
              src="../../static/img/password-ts.png"
              mode
            />当前生成限时密码，时间可任意设置，时效性60分钟。
          </view>
          <view class="startimeBox">
            <view class="timetitle">开始时间:</view>
            <input
              name="input"
              disabled
              :value="starttime"
              @click="sshowPicker = true"
            />
            <view class="picker" @click="sshowPicker = true">
              <img src="/static/img/rili.png" alt class="leaveimg" />
            </view>
          </view>
          <view class="passshow" v-if="passshow">
            <view class="passnum">{{ passnumber }}</view>
            <view class="startendTime"
              >密码时效：{{ sTime }} ~ {{ eTime }}</view
            >
          </view>
          <view class="gettwoPass" @click="gettwoPass">密码生成</view>

          <!-- <view class="fresh">更新开门二维码<text @click="setPass()">刷新</text></view> -->
        </view>
      </view>
    </scroll-view>

    <!-- 密码弹窗  3带锁-->
    <uni-popup ref="popup" type="bottom">
      <view class="passPop" @click="closePassPop">
        <p class="title">查看密码</p>
        <view class="tshi">将二维码对准门锁识别开门</view>
        <view class="tshi" style="padding-bottom: 70upx">
          时效5分钟单次二维码</view
        >
        <view class="QRcodebox">
          <image
            src="../../static/img/pass-border.png"
            mode
            class="backborder"
          />
          <view class="QRcode">
            <image :src="QRcode" mode />
          </view>
        </view>
        <view class="erStartEndDate">
          <view>开始时间：{{ currentdateStart }}</view>
          <view>结束时间：{{ currentdateEnd }}</view>
        </view>
        <view class="fresh" @click.stop="getPass(1)">
          更新开门二维码
          <text>刷新</text>
        </view>
      </view>
    </uni-popup>
    <!-- 密码弹窗  2带锁-->
    <uni-popup ref="popuptwo" type="bottom">
      <view class="passPop passPoptwo" @click="closePassPoptwo">
        <p class="title">密码设置</p>
        <view class="tshi" style="padding-top: 60upx">
          <image
            src="../../static/img/password-ts.png"
            mode
          />当前生成限时密码，在有效时间内可重复使用
        </view>
        <view class="startimeBox">
          <view class="timetitle">开始时间:</view>
          <input name="input" disabled :value="sTime" />
          <!--  <view class="picker" @click.stop="sshowPicker=true">
            <img src="/static/img/rili.png" alt class="leaveimg" />
          </view> -->
        </view>
        <view class="startimeBox">
          <view class="timetitle">结束时间:</view>
          <input name="input" disabled :value="eTime" />
          <!-- <view class="picker" @click.stop="sshowPicker=true">
		    <img src="/static/img/rili.png" alt class="leaveimg" />
		  </view> -->
        </view>
        <view class="passshow" v-if="passshow">
          <view class="passnum">{{ passnumber }}#</view>
          <!--  <view class="startendTime">密码时效：{{sTime}} ~ {{eTime}}</view> -->
        </view>
        <view class="gettwoPass" @click.stop="gettwoPass">密码生成</view>

        <!-- <view class="fresh">更新开门二维码<text @click="setPass()">刷新</text></view> -->
      </view>
    </uni-popup>
    <!-- 五代锁 -->
    <uni-popup ref="popupfive" type="bottom">
      <view class="passPop passPoptwo" @click="closePassPoptwo">
        <p class="title">密码设置</p>
        <view class="tshi" style="padding-top: 60upx">
          <image
            src="../../static/img/password-ts.png"
            mode
          />当前生成限时密码，在有效时间内可重复使用
        </view>
        <view class="startimeBox">
          <view class="timetitle">开始时间:</view>
          <input name="input" disabled :value="sTime" />
        </view>
        <view class="startimeBox">
          <view class="timetitle">结束时间:</view>
          <input name="input" disabled :value="eTime" />
        </view>
        <view class="passshow" v-if="passshow">
          <view class="passnum">{{ passnumber }}#</view>
        </view>
        <view class="gettwoPass" @click.stop="closeFunc('popupfive')"
          >返回上一步</view
        >
      </view>
    </uni-popup>
    <!-- 二代锁密码设置日历 -->
    <mx-date-picker
      :show="sshowPicker"
      type="datetime"
      :value="starttime"
      :show-tips="true"
      :begin-text="'入住'"
      :end-text="'离店'"
      :show-seconds="false"
      @confirm="lonSelected"
      @cancel="lonSelected"
      format="yyyy-mm-dd hh:ii:ss"
    />
  </view>
</template>

<script>
import amap from "../../components/amap-wx.js";
import { mapState, mapMutations, mapActions } from "vuex";
import camera from "../../components/scan-frame/scan-frame.vue";
import login from "../../components/login/login.vue";
import uCharts from "../../js_sdk/u-charts/u-charts/u-charts.min.js";
import uniPopup from "@/components/uni-popup/uni-popup.vue";
import MxDatePicker from "@/components/mx-datepicker/mx-datepicker.vue";
const plugin = requirePlugin("myPlugin");
const ketingLock = requirePlugin("keting");
const createPlugin = requirePlugin("ax6");
const ax6Plugin = createPlugin();
var _self;
var canvaArcbar1;

export default {
  name: "home",
  components: {
    camera,
    login,
    uniPopup,
    MxDatePicker,
  },
  data() {
    return {
      currentdateStart: "",
      currentdateEnd: "",
      sshowPicker: false,
      starttime: this.$moment().format("YYYY-MM-DD HH:00:00"),
      amapPlugin: null,
      orderinfo: [],
      key: [],
      cWidth3: "", //圆弧进度图
      cHeight3: "", //圆弧进度图
      arcbarWidth: "", //圆弧进度图，进度条宽度,此设置可使各端宽度一致
      pixelRatio: 1,
      data: {
        series: [
          {
            name: "剩余时间",
            data: 0.29,
            color: "#4382FF",
          },
        ],
      },
      time: "",
      inter: "",
      options: "",
      order: "",
      hour: "",
      minutes: "",
      QRcode: null,
      pwdSwitchStatus: 0,
      sTime: "",
      eTime: "",
      passshow: false,
      passnumber: "",
      entryTime: "",
      leaveTime: "",
      popuptwo: false,
      keting: false,
    };
  },
  computed: {
    ...mapState({
      user: "user",
    }),
    http() {
      if (this.order) {
        if (/http/.test(this.order.openKey)) {
          return "http";
        } else if (this.keting.extColA) {
          return "keting";
        } else if (this.order.openKeyType == "2") {
          if (this.order.openKeyDetailType == "3") {
            return "jianpai2";
          } else if (this.order.openKeyDetailType == "4") {
            return "jianpai";
          } else if (this.order.openKeyDetailType == "5") {
            return "jianpai3";
          } else if (this.order.openKeyDetailType == "6") {
            return "bluetooth";
          } else if (this.order.openKeyDetailType == "7") {
            return "kejixia";
          }else if (this.order.openKeyDetailType == "8") {
            return "ax6";
          }
        } else if (!this.order.openKey) {
          return "wu";
        } else {
          return "mima";
        }
      }
    },
    zanwuopen() {
      this.hour = this.$moment(this.order.entryTime).hour();
      this.minutes = this.$moment(this.order.entryTime).minutes();
      if (this.minutes <= 9) {
        this.minutes = "0" + this.minutes;
      }
      if (this.hour <= 9) {
        this.hour = "0" + this.hour;
      }
      console.log(this.$moment(this.order.entryTime).valueOf());
      if (
        new Date().getTime() >= this.$moment(this.order.entryTime).valueOf() &&
        new Date().getTime() <= this.$moment(this.order.leaveTime).valueOf()
      ) {
        return false;
      } else {
        return true;
      }
    },
  },

  onLoad(options) {
	  console.log(options)
	  this.keting=options
    wx.getSetting({
      success(res) {
        console.log(res.authSetting);
      },
    });
    // wx.closeBLEConnection({
    //   deviceId: "6E400091-B5A3-F393-E0A9-E50E24DCCA9E",
    //   success(res) {
    //     console.log("关闭蓝牙");
    //     console.log(res);
    //   },
    //   fail(res) {
    //     console.log("关闭蓝牙失败");
    //     console.log(res);
    //   },
    // });
  },
  onShow() {
    this.order = "";
    this.key = [];
    if (!this.user) return;
    this.getOrderInfo();
    this.starttime = this.$moment().format("YYYY-MM-DD HH:00:00");
    let now = new Date();

    let year = now.getFullYear(); //年
    let month = now.getMonth() + 1; //月
    let day = now.getDate(); //日

    let hh = now.getHours(); //时
    let mm = now.getMinutes();

    let ss = now.getSeconds(); //分

    let clock = year + "-";
    let datatime = year + "-";

    if (month < 10) {
      clock += "0";
      datatime += "0";
    }
    clock += month + "-";
    datatime += month + "-";

    if (day < 10) clock += "0";

    clock += day + "";
    datatime += day + "";

    if (hh < 10) clock += "0";

    clock += hh + ":";
    if (mm < 10) clock += "0";
    clock += mm + ":";

    if (ss < 10) clock += "0";
    clock += ss;
    this.currentdateStart = clock;
    let currentTime = this.$moment(clock).format("YYYY-MM-DD HH:mm:ss");
    // let result = [];
    for (let i = 0; i < 300; i++) {
      this.currentdateEnd =
        datatime +
        this.$moment(currentTime).add(i, "seconds").format("HH:mm:ss");
    }
  },

  methods: {
    ...mapMutations({
      setUser: "setUser",
    }),
    bluetoothopenhx() {
      const options = {
        lockMac: this.order.mac, //重点注意：mac地址中的字母为小写字母格式
        keyGroupId: this.order.keyGroupId ? this.order.keyGroupId : undefined,
        authCode: this.order.extColA,
        aesKey: this.order.extColB,
        skipDiscovery: true, // 使用直连方式，需要同时提供lockMac
      };
      console.log(options)
      // 3.初始化插件
      const myLock = new ax6Plugin(options);
      uni.showLoading({
        title: "开锁中",
      });
      // 4.监听ready事件
      myLock.on("ready", () => {
        // 5.调用API
        // 插件所有的API都需要在插件响应ready事件之后才可以调用成功
        console.log("ready");
        myLock
          .openLock()
          .then((res) => {
            // 成功时调用
            console.log(res);
            uni.hideLoading();
            uni.showToast({
              title: "开锁成功",
              icon: "none",
            });
            myLock.disconnect();
            //记录
            this.$http
              .post(
                "/pwd/bluetooth/addUnlockRecord",
                {
                  room_id: this.order.jpRoomId,
                  room_name: this.order.homeInfo.homeNumber,
                  created_at: this.$moment().format("YYYY-MM-DD HH:mm:ss"),
                  imei: this.order.lockImei,
                  name: this.order.tenantInfoList.find(
                    (item) => item.tenantPhoneNumber == this.user
                  ).tenantName,
                  op_time: Date.parse(new Date()) / 1000,
                  result: "1",
                  tenantPhoneNumber: this.user,
                  platformSourceType: "13",
                  location: this.order.hotelAddress,
                  registered: "1",
                  unlock_type: "12",
                  lockType: "172",
                },
                {
                  header: {
                    "content-type": "application/json;charset=UTF-8",
                  } /* 会覆盖全局header */,
                  dataType: "json",
                  responseType: "text",
                }
              )
              .then((res) => {});
          })
          .catch((err) => {
            console.log(res);
            uni.hideLoading();
            myLock.disconnect();

            // 失败时调用
            // debug
          });
      });
    },
    lonSelected(e) {
      //选择
      this.sshowPicker = false;
      if (e) {
        //选择的值
        this.date = e.value;
        console.log("value => " + e.value);
        this.starttime = e.value;
        //原始的Date对象
      }
    },
    // 获取密码  3带锁
    getPass(type) {
      wx.showLoading({
        title: "获取中",
        mask: true,
      });
      this.$http
        .post(
          "/pwd/homePwd/select",
          {
            homeId: this.order.homeId,
            hotelId: this.order.homeInfo.hotelId,
            jpRoomId: this.order.jpRoomId,
            lockImei: this.order.lockImei,
            mac: this.order.mac,
            offlinePwdTypeEnum: "ONE",
            orderNumber: this.order.orderNumber,
            password: "",
            phoneNumber: this.user,
          },
          {
            header: {
              "content-type": "application/json;charset=UTF-8",
            } /* 会覆盖全局header */,
            dataType: "json",
            responseType: "text",
          }
        )
        .then((res) => {
          let data = res.data;
          wx.hideLoading();
          if (data.code == 0) {
            this.openPassPop();
            this.QRcode = data.msg;
            if (type == 1) {
              this.currentdateStart = "";
              this.currentdateEnd = "";
              let freshDate = new Date();
              this.currentdateStart = this.$moment(freshDate).format(
                "YYYY-MM-DD HH:mm:ss"
              );
              this.currentdateEnd = this.$moment(
                new Date(freshDate.getTime() + 300000)
              ).format("YYYY-MM-DD HH:mm:ss");
            }
          } else {
            wx.showToast({
              icon: "none",
              title: data.msg,
              duration: 2000,
              mask: true,
            });
          }
        })
        .catch((err) => {});
    },
    setPass() {
      this.openPassPoptwo();
      this.twoPass();
    },
    //五代锁
    setPassfive() {
      if (!this.order.lockImei) {
        uni.showToast({
          title: "该房屋未配置锁",
          duration: 2000,
          icon: "none",
        });
        return;
      }
      this.openPassPopfive();
      this.Passfive();
    },
    // 打开弹窗获取已经设定密码
    twoPass() {
      this.$http
        .get(
          "/pwd/lastPwd/select",
          {
            homeId: this.order.homeId,
            phoneNumber: this.user,
            leaveTime: this.leaveTime,
            entryTime: this.entryTime,
          },
          {
            header: {
              "content-type": "application/json;charset=UTF-8",
            } /* 会覆盖全局header */,
            dataType: "json",
            responseType: "text",
          }
        )
        .then((res) => {
          let data = res.data;
          if (data.code == 0) {
            if (data.password != "null") {
              this.passshow = true;
              this.passnumber = data.data.password;
              this.sTime = this.$moment(data.data.startTime).format(
                "YYYY-MM-DD HH:mm:ss"
              );
              this.eTime = this.$moment(data.data.endTime).format(
                "YYYY-MM-DD HH:mm:ss"
              );
            }
          } else {
            wx.showToast({
              image: "/static/img/warn.png",
              title: data.msg,
              duration: 2000,
              mask: true,
            });
          }
        })
        .catch((err) => {});
    },
    //五代锁
    Passfive() {
      this.$http
        .get(
          "/pwd/getPwd",
          {
            orderNumber: this.order.orderNumber,
            customPhoneNumber: uni.getStorageSync("phone"),
          },
          {
            header: {
              "content-type": "application/json;charset=UTF-8",
            } /* 会覆盖全局header */,
            dataType: "json",
            responseType: "text",
          }
        )
        .then((res) => {
          let data = res.data;
          if (data.code == 0) {
            if (data.password != "null") {
              this.passshow = true;
              this.passnumber = data.msg;
              console.log("五代锁密码");
              this.sTime = this.$moment(this.order.entryTime).format(
                "YYYY-MM-DD HH:mm:ss"
              );
              this.eTime = this.$moment(this.order.leaveTime).format(
                "YYYY-MM-DD HH:mm:ss"
              );
            }
          } else {
            wx.showToast({
              image: "/static/img/warn.png",
              title: data.msg,
              duration: 2000,
              mask: true,
            });
          }
        });
    },
    gettwoPass() {
      wx.showLoading({
        title: "加载中",
        mask: true,
      });
      this.$http
        .post(
          "/pwd/homePwd/select",
          {
            homeId: this.order.homeId,
            hotelId: this.order.homeInfo.hotelId,
            jpRoomId: this.order.jpRoomId,
            lockImei: this.order.lockImei,
            mac: this.order.mac,
            offlinePwdTypeEnum: "3",
            orderNumber: this.order.orderNumber,
            password: "",
            phoneNumber: this.user,
            startTime: this.starttime,
          },
          {
            header: {
              "content-type": "application/json;charset=UTF-8",
            } /* 会覆盖全局header */,
            dataType: "json",
            responseType: "text",
          }
        )
        .then((res) => {
          wx.hideLoading();
          let data = res.data;
          if (data.code == 0) {
            this.twoPass();
          } else {
            wx.showToast({
              icon: "none",
              title: data.msg,
              duration: 3000,
            });
          }
        })
        .catch((err) => {});
    },
    //打开密码弹窗 3带锁
    openPassPop() {
      this.$refs.popup.open();
    },
    openPassPoptwo() {
      this.$refs.popuptwo.open();
      // this.popuptwo = true;
    },
    //五代锁
    openPassPopfive() {
      this.$refs.popupfive.open();
    },
    closePassPoptwo() {
      this.$refs.popuptwo.close();
    },
    closePassPop() {
      this.$refs.popup.close();
    },
    getServerData() {
      this.showArcbar("canvasArcbar1", this.data);
    },

    getOrderInfo() {
      wx.showLoading({
        title: "加载中",
        mask: true,
      });
      this.$http
        .post(
          "/app/getOrderInfo",
          this.$qs.stringify({
            tenantPhoneNumber: this.user,
          }),
          {
            header: {} /* 会覆盖全局header */,
            dataType: "json",
            responseType: "text",
          }
        )
        .then((res) => {
          wx.hideLoading();
          setTimeout(function () {
            wx.stopPullDownRefresh();
          }, 500);
          let datas = res.data;
          if (datas.code == 0) {
            this.entryTime = this.$moment(
              datas.data.orderList.entryTime
            ).format("YYYY/MM/DD HH:mm");
            this.leaveTime = this.$moment(
              datas.data.orderList.leaveTime
            ).format("YYYY/MM/DD HH:mm");
            this.key = [];
            this.order = "";
            console.log(datas.data.orderList);
            this.pwdSwitchStatus = datas.data.orderList.pwdSwitchStatus;
            if (!datas.data.orderList) {
              return;
            }
            this.order = datas.data.orderList;
            console.log(234234);
            let data = datas.data.orderList;
            // if (!data.openKey && this.order.openKeyType != 2) {
            // 	return;
            // }
            let key = data.openKey;
            if (this.order.openKey) {
              this.key = this.order.openKey.split("");
            }

            let start = new Date(this.$moment(this.order.entryTime)).getTime();
            let end = new Date(this.$moment(this.order.leaveTime)).getTime();
            let now = new Date().getTime();
            let bi = ((end - now) / (end - start)).toFixed(2);
            var hao =
              new Date(this.$moment(this.order.leaveTime)).getTime() -
              new Date().getTime();
            //计算出小时数
            var days = Math.floor(hao / (24 * 3600 * 1000));
            var leave1 = hao % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
            var hours = Math.floor(leave1 / (3600 * 1000));
            //计算相差分钟数
            var leave2 = hao % (3600 * 1000); //计算小时数后剩余的毫秒数
            var minutes = Math.floor(leave2 / (60 * 1000));
            //计算相差秒数
            var leave3 = hao % (60 * 1000); //计算分钟数后剩余的毫秒数
            var seconds = Math.round(leave3 / 1000);
            this.time =
              days * 24 + hours + "小时" + minutes + "分钟" + seconds + "秒";
            console.log(this.time);
            console.log(2343);
            this.data = {
              series: [
                {
                  name: "剩余时间",
                  data: bi,
                  color: "#4382FF",
                },
              ],
            };

            _self = this;
            this.cWidth3 = uni.upx2px(300); //这里要与样式的宽高对应
            this.cHeight3 = uni.upx2px(300); //这里要与样式的宽高对应
            this.arcbarWidth = uni.upx2px(24);
            this.getServerData();

            // if (this.key.length < 6 && this.order.openKeyType != 2) {
            // 	return;
            // }
            this.inter = setInterval(() => {
              this.gettime(this.order);
            }, 1000);
          } else {
            this.key = [];
            this.order = "";

            wx.showToast({
              image: "/static/img/warn.png",
              title: data.msg,
              duration: 2000,
              mask: true,
            });
          }
        });
    },
    showArcbar(canvasId, chartData) {
      let _self = this;
      canvaArcbar1 = new uCharts({
        $this: _self,
        canvasId: canvasId,
        type: "arcbar",
        fontSize: 11,
        legend: false,
        background: "#4382FF",
        pixelRatio: _self.pixelRatio,
        series: chartData.series,
        animation: true,
        width: _self.cWidth3 * _self.pixelRatio,
        height: _self.cHeight3 * _self.pixelRatio,
        dataLabel: true,
        title: {
          name: Math.round(chartData.series[0].data * 100) + "%", //这里我自动计算了，您可以直接给任意字符串
          color: chartData.series[0].color,
          fontSize: 25 * _self.pixelRatio,
        },
        subtitle: {
          name: chartData.series[0].name, //这里您可以直接给任意字符串
          color: "#666666",
          fontSize: 15 * _self.pixelRatio,
        },
        extra: {
          arcbar: {
            type: "circle", //整圆类型进度条图
            width: _self.arcbarWidth * _self.pixelRatio, //圆弧的宽度
            startAngle: 0.5, //整圆类型只需配置起始角度即可
          },
        },
      });
    },
    toorderitem(item) {
      wx.navigateTo({
        url: "/pages/orderitem/orderitem?item=" + JSON.stringify(item),
      });
    },
    gettime(options) {
      if (!this.order) {
        return;
      }
      let start = new Date(this.$moment(this.order.entryTime)).getTime();
      let end = new Date(this.$moment(this.order.leaveTime)).getTime();
      let now = new Date().getTime();
      let bi = ((end - now) / (end - start)).toFixed(2);
      var hao =
        new Date(this.$moment(this.order.leaveTime)).getTime() -
        new Date().getTime();
      var hao =
        new Date(this.$moment(this.order.leaveTime)).getTime() -
        new Date().getTime();
      //计算出小时数
      var days = Math.floor(hao / (24 * 3600 * 1000));
      var leave1 = hao % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
      var hours = Math.floor(leave1 / (3600 * 1000));
      //计算相差分钟数
      var leave2 = hao % (3600 * 1000); //计算小时数后剩余的毫秒数
      var minutes = Math.floor(leave2 / (60 * 1000));
      //计算相差秒数
      var leave3 = hao % (60 * 1000); //计算分钟数后剩余的毫秒数
      var seconds = Math.round(leave3 / 1000);
      this.time =
        days * 24 + hours + "小时" + minutes + "分钟" + seconds + "秒";
      this.data = {
        series: [
          {
            name: "剩余时间",
            data: bi,
            color: "#4382FF",
          },
        ],
      };
      if (this.order.openKey) {
        this.key = this.order.openKey.split("");
      }
      _self = this;
      this.cWidth3 = uni.upx2px(300); //这里要与样式的宽高对应
      this.cHeight3 = uni.upx2px(300); //这里要与样式的宽高对应
      this.arcbarWidth = uni.upx2px(24);
    },
    call() {
      wx.makePhoneCall({
        phoneNumber: "400 188 2160", //仅为示例
      });
    },
    bluetoothopen() {
      wx.getConnectedBluetoothDevices({
        //services:[],
        success: function (res) {
          console.log("已连接");
          console.log(res);
        },
        fail(res) {
          console.log("未连接");
          console.log(res);
        },
      });
      wx.showLoading({
        title: "设备连接中",
        mask: true,
      });
      this.$http
        .post(
          "/pwd/homePwd/select",
          {
            homeId: this.order.homeId,
            hotelId: this.order.homeInfo.hotelId,
            jpRoomId: this.order.jpRoomId,
            lockImei: this.order.lockImei,
            mac: this.order.mac,
            offlinePwdTypeEnum: "6",
            orderNumber: this.order.orderNumber,
            password: "",
            phoneNumber: this.user,
          },
          {
            header: {
              "Content-Type": "application/json;charset=UTF-8",
            } /* 会覆盖全局header */,
            dataType: "json",
            responseType: "text",
          }
        )
        .then((res) => {
          console.log(res);
          let data = res.data;
          if (data.code == 0) {
            console.log(data.msg);

            this.open(data.msg);
            // wx.showToast({
            //   image: "/static/img/success.png",
            //   title: "添加成功",
            //   duration: 2000,
            // });
          } else {
            wx.showToast({
              icon: "none",
              title: data.msg,
              duration: 2000,
            });
          }
        });
    },

    open(msg) {
      let that = this;
      var setTimeoutid = undefined;
      let serviceId = "";
      let deviceId = "";
      this.closeBluetoothAdapter();
      wx.openBluetoothAdapter({
        success(res) {
          wx.onBluetoothDeviceFound((res) => {
            res.devices.forEach((device) => {
              console.log(device);
              console.log(device.deviceId);
              console.log(device.localName);
              if (device.localName == that.order.lockImei) {
                console.log("device", device);
                deviceId = device.deviceId;
                clearTimeout(setTimeoutid);
                wx.createBLEConnection({
                  deviceId: device.deviceId,
                  success: (res) => {
                    console.log(res);
                    setTimeout(() => {
                      wx.getBLEDeviceServices({
                        // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
                        deviceId: device.deviceId,
                        success(res) {
                          console.log("device services:", res.services);
                          serviceId = res.services[0].uuid;

                          wx.getBLEDeviceCharacteristics({
                            // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
                            deviceId: device.deviceId,
                            // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
                            serviceId: serviceId,
                            success(res) {
                              console.log(
                                "device getBLEDeviceCharacteristics:",
                                res.characteristics
                              );
                              let characteristicId = "";
                              for (
                                let i = 0;
                                i < res.characteristics.length;
                                i++
                              ) {
                                if (res.characteristics[i].properties.write) {
                                  characteristicId =
                                    res.characteristics[i].uuid;
                                }
                                if (res.characteristics[i].properties.notify) {
                                  // 启用蓝牙设备的通知功能，之后才能监听到蓝牙数据的变化
                                  wx.notifyBLECharacteristicValueChange({
                                    deviceId: device.deviceId,
                                    serviceId: serviceId,
                                    characteristicId:
                                      res.characteristics[i].uuid,
                                    state: true,
                                    success(res) {
                                      console.log(
                                        "notifyBLECharacteristicValueChange success",
                                        res.errMsg
                                      );
                                    },
                                    fail(res) {
                                      console.log(
                                        "notifyBLECharacteristicValueChange fail",
                                        res.errMsg
                                      );
                                    },
                                  });
                                  // 监听蓝牙设备的数据变化
                                  wx.onBLECharacteristicValueChange(
                                    (characteristic) => {
                                      console.log("监听了");
                                      console.log(characteristic);
                                      that.getresult(
                                        that.arrayBufferToHexString(
                                          characteristic.value
                                        )
                                      );
                                    }
                                  );
                                  console.log(
                                    "device.deviceId",
                                    device.deviceId
                                  );
                                  console.log("serviceId", serviceId);
                                  console.log(
                                    "characteristicId",
                                    characteristicId
                                  );
                                  let value = msg;
                                  let index = 120;
                                  let reg = RegExp(
                                    "[\\s\\S]{" +
                                      index +
                                      "}|([\\s\\S]{1," +
                                      (index - 1) +
                                      "})",
                                    "img"
                                  );
                                  let values = [];
                                  let arr = reg.exec(value);
                                  if (arr) {
                                    values.push(arr[0]);
                                    while ((arr = reg.exec(value)) !== null) {
                                      values.push(arr[0]);
                                    }
                                  } else {
                                    values.push(value);
                                  }
                                  let vil = values.length;

                                  for (let i = 0; i < vil; i++) {
                                    console.log(values[i]);
                                    wx.writeBLECharacteristicValue({
                                      // 这里的 deviceId 需要在 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
                                      deviceId: device.deviceId,
                                      // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
                                      serviceId: serviceId,
                                      // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
                                      characteristicId: characteristicId,
                                      // 这里的value是ArrayBuffer类型
                                      value: that.hexCharCodeToStr(values[i]),
                                      success(res) {
                                        console.log(
                                          "writeBLECharacteristicValue success",
                                          res.errMsg
                                        );

                                        if (i == vil - 1) {
                                          // if (wx.offBLEConnectionStateChange) {
                                          //   wx.offBLEConnectionStateChange(
                                          //     (res) => {
                                          //       console.log(
                                          //         new Date().getTime(),
                                          //         "取消订阅服务成功",
                                          //         res
                                          //       );
                                          //     }
                                          //   );
                                          //   wx.offBLECharacteristicValueChange(
                                          //     (res) => {
                                          //       console.log(
                                          //         new Date().getTime(),
                                          //         "取消订阅服务成功",
                                          //         res
                                          //       );
                                          //     }
                                          //   );
                                          //   wx.closeBLEConnection({
                                          //     deviceId: device.deviceId,
                                          //     success(res) {
                                          //       console.log("关闭蓝牙");
                                          //       console.log(res);
                                          //     },
                                          //     fail(res) {
                                          //       console.log("关闭蓝牙失败");
                                          //       console.log(res);
                                          //     },
                                          //   });
                                          //   wx.closeBluetoothAdapter({
                                          //     success(res) {
                                          //       console.log("关闭连接");
                                          //       console.log(res);
                                          //     },
                                          //   });
                                          // }
                                        }

                                        // that.$http
                                        //   .post(
                                        //     `/pwd/homePwd/select`,
                                        //     {
                                        //       homeId: this.order.homeId,
                                        //       hotelId: this.order.homeInfo
                                        //         .hotelId,
                                        //       jpRoomId: this.order.jpRoomId,
                                        //       lockImei: this.order.lockImei,
                                        //       mac: this.order.mac,
                                        //       offlinePwdTypeEnum: "6",
                                        //       orderNumber: this.order.orderNumber,
                                        //       password: "",
                                        //       phoneNumber: this.user,
                                        //       startTime: this.starttime,
                                        //     },
                                        //     {
                                        //       header: {
                                        //         "Content-Type":
                                        //           "application/json;charset=UTF-8",
                                        //       } /* 会覆盖全局header */,
                                        //       dataType: "json",
                                        //       responseType: "text",
                                        //     }
                                        //   )
                                        //   .then((res) => {});
                                      },
                                      fail(res) {
                                        console.log(JSON.stringify(res));
                                        wx.closeBLEConnection({
                                          deviceId: deviceId,
                                          success(res) {
                                            console.log("关闭蓝牙");
                                            console.log(res);
                                          },
                                          fail(res) {
                                            console.log("关闭蓝牙失败");
                                            console.log(res);
                                          },
                                        });
                                        wx.closeBluetoothAdapter({
                                          success(res) {
                                            console.log("关闭蓝牙");
                                            console.log(res);
                                          },
                                        });
                                      },
                                    });
                                  }
                                }
                              }

                              console.log("characteristicId", characteristicId);
                            },
                          });
                        },
                        fail(res) {
                          console.log("device services:", res.services);
                        },
                      });
                    }, 0);
                  },
                  fail: (res) => {
                    console.log(res);
                  },
                });

                wx.stopBluetoothDevicesDiscovery();
              }
            });
          });

          setTimeoutid = setTimeout(() => {
            wx.hideLoading();
            wx.showToast({
              title: "连接超时",
              duration: 2000,
              icon: "none",
            });
            wx.stopBluetoothDevicesDiscovery();
          }, 15000);
          const templateUUID = "6E40***1-B5A3-F393-E0A9-E50E24DCCA9E";
          const roomid = that.order.lockImei.substring(
            that.order.lockImei.length - 3,
            that.order.lockImei.length
          );
          let uuid = templateUUID.replace("***", roomid);
          console.log(uuid);
          wx.startBluetoothDevicesDiscovery({
            services: [uuid],
            allowDuplicatesKey: false,
          });
        },
        fail(res) {
          console.log(res);
          if (res.errCode == "10001") {
            uni.showModal({
              title: "提示",
              content: "请打开蓝牙",
              success: function (res) {
                uni.hideLoading();

                if (res.confirm) {
                  console.log("用户点击确定");
                } else if (res.cancel) {
                  console.log("用户点击取消");
                }
              },
            });
          }
        },
      });
    },
    closeBluetoothAdapter(deviceId) {
      wx.getConnectedBluetoothDevices({
        success(res) {
          console.log(res);
        },
      });
      console.log(new Date().getTime(), "关闭蓝牙");

      if (wx.offBLEConnectionStateChange) {
        wx.offBLEConnectionStateChange();
      }
      console.log(new Date().getTime(), "关闭搜索蓝牙");
      wx.stopBluetoothDevicesDiscovery({
        success(res) {
          console.log(new Date().getTime(), "关闭搜索", res);
        },
        fail(err) {
          console.log(new Date().getTime(), "关闭搜索失败", err);
        },
      });
      if (deviceId) {
        wx.closeBLEConnection({
          deviceId,
          success(res) {
            console.log(new Date().getTime(), "断开连接成功", res);
          },
          fail(err) {
            console.log(new Date().getTime(), "断开连接失败", err);
          },
        });
      }
      wx.closeBluetoothAdapter({
        success(res) {
          console.log(new Date().getTime(), "关闭蓝牙成功", res);
        },
      });
    },

    //转进制发送
    hexCharCodeToStr(str) {
      if (!str) {
        return new ArrayBuffer(0);
      }
      console.log(str.length);
      if (str.length % 2 != 0) {
        str = str + "0";
      }
      let len = str.length / 2;
      let buffer = new ArrayBuffer(len);
      let dataView = new DataView(buffer);
      for (let i = 0; i < len; i++) {
        let z = str.substr(i * 2, 2);
        let code = parseInt(z, 16);
        dataView.setUint8(i, code);
      }
      console.log(str);
      console.log(buffer);

      return buffer;
    },
    //转进制接收
    arrayBufferToHexString(buffer) {
      let bufferType = Object.prototype.toString.call(buffer);
      if (buffer != "[object ArrayBuffer]") {
        return;
      }
      let dataView = new DataView(buffer);
      var hexStr = "";
      for (var i = 0; i < dataView.byteLength; i++) {
        var str = dataView.getUint8(i);
        var hex = (str & 0xff).toString(16);
        hex = hex.length === 1 ? "0" + hex : hex;
        hexStr += hex;
      }
      return hexStr.toUpperCase();
    },
    getresult(orderresult) {
      wx.showToast({
        title: "开锁成功",
        duration: 3000,
      });
      this.$http.get(
        "/pwd/blueToothOpenLockResult",
        {
          lockImei: this.order.lockImei,

          phoneNumber: this.user,
          orderresult: orderresult,
        },
        {
          header: {
            "Content-Type": "application/json;charset=UTF-8",
          } /* 会覆盖全局header */,
          dataType: "json",
          responseType: "text",
        }
      );
    },
    // kejixia点击开锁
    async toOpenDoor() {
      if (!this.order.lockImei) {
        uni.showToast({
          title: "该房屋未配置锁",
          duration: 2000,
          icon: "none",
        });
        return;
      }
      uni.showLoading({
        title: "正在开启智能锁",
        mask: true,
      });
      let res = await this.$http.get(
        "/pwd/getLockData",
        {
          imei: this.order.lockImei,
        },
        {
          header: {
            "Content-Type": "application/json;charset=UTF-8",
          } /* 会覆盖全局header */,
          dataType: "json",
          responseType: "text",
        }
      );
      let lockData = res.data.msg;
      console.log(lockData);
      // this.toCheckLockTime(lockData);

      plugin.controlLock(plugin.CONTROL_ACTION_OPEN, lockData, (res) => {
        console.log(res);

        if (res.errorCode === 0) {
          uni.showToast({
            title: "已开锁",
            duration: 2000,
          });
          setTimeout(() => {
            console.log("获取记录");
            this.toReadRecord(lockData, this.order.lockImei);
          }, 0);
          // this.setData({
          //   state: `已开锁--操作时间:${Date.now() - start}`
          // });
        } else {
          this.toReadRecord(lockData, this.order.lockImei);

          uni.showToast({
            title: res.errorMsg,
            duration: 2000,
            icon: "none",
          });
          // this.setData({
          //   state: `开锁失败:${res.errorMsg}`
          // });
        }
      });
    },
    //keting锁

    async toOpenDoorketing() {
      //调用插件初始化方法
      const initRes = await ketingLock.Init(
        "8330266e3d3e474dac677d2fd8fcf814",
        "OThjZjdkMWFkZGJjNDVhZmJmNDM0YWI5YTdjMDRlYjY="
      );
      console.log(initRes);
      if (initRes.isFail) {
        //插件初始化失败
        return;
      }
      wx.showLoading({
        title: "开门中...",
      });
      const openRes = await ketingLock.OpenLock(this.keting.extColA); //调用开锁接口
      console.log(openRes)
      wx.hideLoading();
      if (openRes.isFail) {
        wx.showToast({
        icon: "none",
        title: openRes.message,
        duration: 2000,
        mask: true,
      });
	  this.$http
	    .post(
	      "/pwd/bluetooth/addUnlockRecord",
	      {
	  			 "room_id":this.order.homeId,
	  			   "room_name":this.order.homeInfo.homeNumber,
	  			   "created_at": this.$moment().format('YYYY-MM-DD HH:mm:ss'),
	  			   "imei": this.keting.extColA,
	  			   "name": this.order.tenantInfoList.find(item=>item.tenantPhoneNumber==this.user).tenantName,
	  			   "op_time": Date.parse(new Date())/1000,
	  			   "result": "0",
	  			   "tenantPhoneNumber": this.user,
	  			   "platformSourceType":"5",
	  			   "location":this.order.hotelAddress,
	  			   "registered":"1",
	  			   "unlock_type": "12"
	      },
	      {
	        header: {
	          "content-type": "application/json;charset=UTF-8",
	        } /* 会覆盖全局header */,
	        dataType: "json",
	        responseType: "text",
	      }
	    )
	    .then((res) => {
	    })
        //接口调用失败，openRes.message会给出失败原因
        return;
      }
	  this.$http
	    .post(
	      "/pwd/bluetooth/addUnlockRecord",
	      {
	  			 "room_id":this.order.homeId,
	  			   "room_name":this.order.homeInfo.homeNumber,
	  			   "created_at": this.$moment().format('YYYY-MM-DD HH:mm:ss'),
	  			   "imei": this.keting.extColA,
	  			   "name": this.order.tenantInfoList.find(item=>item.tenantPhoneNumber==this.user).tenantName,
	  			   "op_time": Date.parse(new Date())/1000,
	  			   "result": "1",
	  			   "tenantPhoneNumber": this.user,
	  			   "platformSourceType":"5",
	  			   "location":this.order.hotelAddress,
	  			   "registered":"1",
	  			   "unlock_type": "12"
	      },
	      {
	        header: {
	          "content-type": "application/json;charset=UTF-8",
	        } /* 会覆盖全局header */,
	        dataType: "json",
	        responseType: "text",
	      }
	    )
	    .then((res) => {
	    })
      wx.showToast({
        icon: "none",
        title: "开锁成功",
        duration: 2000,
        mask: true,
      });
    },
    // 校准锁时间
    async toCheckLockTime(lockData) {
      let res = await this.$http.get(
        "/pwd/getSystemCurrentTime",
        {},
        {
          header: {
            "Content-Type": "application/json;charset=UTF-8",
          } /* 会覆盖全局header */,
          dataType: "json",
          responseType: "text",
        }
      );
      console.log(res);
      plugin.setLockTime(new Date(res.data.data), lockData, (res) => {
        console.log(res);

        if (res.errorCode === 0) {
        } else {
        }
      });
    },
    // 读取操作记录
    async toReadRecord(lockData, lockImei) {
      // this.setData({
      //   state: "正在读取锁内操作记录"
      // });
      const start = Date.now(); // 获取操作记录
      setTimeout(async (item) => {
        plugin.getOperationLog(
          plugin.RECORD_TYPE_NEW,
          lockData,
          async (res) => {
            console.log(res);

            if (res.errorCode === 0) {
              // this.setData({
              //   state: `操作记录已获取--操作时间::${Date.now() - start}`,
              //   logList: JSON.parse(res.log)
              // });
              // uploadOperation({
              //   lockId: this.keyInfo.lockId,
              //   records: res.log,
              // })
              //   .then((res) => {
              //     this.setData({
              //       state: "操作记录已上传",
              //     });
              //   })
              //   .catch((err) => {});
              console.log(2222);
              console.log(res.log);
              let tenant = this.order.tenantInfoList.find((item) => {
                return item.tenantPhoneNumber == uni.getStorageSync("phone");
              });
              console.log(
                JSON.parse(res.log).map((item) => {
                  return {
                    recordType: item.recordType,
                    operateDate: item.operateDate,
                    lockId: lockImei,
                    opName: item.password ? "" : tenant.tenantName,
                    password: item.password,
                  };
                })
              );

              let resaddUnlockRecord = await this.$http.post(
                "/pwd/addUnlockRecord?tenantPhoneNumber=" +
                  uni.getStorageSync("phone"),
                JSON.parse(res.log).map((item) => {
                  return {
                    recordType: item.recordType,
                    operateDate: item.operateDate,
                    lockId: lockImei,
                    opName: item.password ? "" : tenant.tenantName,
                    password: item.password,
                  };
                }),
                {
                  header: {
                    "Content-Type": "application/json;charset=UTF-8",
                  } /* 会覆盖全局header */,
                  dataType: "json",
                  responseType: "text",
                }
              );
            } else {
              // this.setData({
              //   state: "读取操作记录失败:" + res.errorMsg,
              // });
              console.log(res.errorMsg);
            }
          }
        );
      }, 200);
    },
    closeFunc(v) {
      this.$refs[v].close();
    },
  },

  onPullDownRefresh() {
    if (!this.user) return;
    this.getOrderInfo();
    if (this.key.length < 6) {
      setTimeout(function () {
        wx.stopPullDownRefresh();
      }, 500);
      return;
    }
    clearInterval(this.inter);
    this.getServerData();
    this.inter = setInterval(() => {
      this.gettime(this.order);
    }, 1000);
    setTimeout(function () {
      wx.stopPullDownRefresh();
    }, 500);
  },

  watch: {
    order() {},
  },
  onUnload() {
    this.closeBluetoothAdapter();
    clearInterval(this.inter);
  },
  onHide() {
    this.closeBluetoothAdapter();
    console.log("hide");
  },
};
</script>

<style lang="scss">
.erStartEndDate {
  text-align: center;
  color: #7a7a7a;
}
.home {
  padding: 10px;
  padding-bottom: 20px;
  .toppart {
    padding: 20rpx;
    border-radius: 8px 8px 8px 8px;
    background: white;
    display: flex;
    flex-direction: column;

    .none {
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      text-align: center;
      margin-top: 80px;
    }
    .sfz {
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      text-align: center;
    }
    .zwsfz {
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      text-align: center;
      margin-top: 20px;
      position: relative;
    }
    .zanwutext {
      position: absolute;
      margin-top: -20rpx;
    }
    .zanwutitle {
      font-size: 48rpx;
      font-family: Alibaba PuHuiTi;
      font-weight: 500;
      color: #3f3d56;
    }
    .zanwutime {
      font-size: 30upx;
      font-family: Alibaba PuHuiTi;
      font-weight: 400;
      color: #443db5;
    }
    .mei {
      font-size: 25px;
      color: #7e7e7e;
      text-align: center;
      margin-top: 40px;
    }

    .zixun {
      font-size: 12px;
      color: #ffb06e;
      margin-top: 10px;
      margin-bottom: 80px;
    }
    .noneimg {
      height: 184px;
      width: 205px;
    }
    .sfzimg {
      height: 456upx;
      margin-left: 20upx;
    }
    .dianwo {
      width: 662rpx;
      height: 415rpx;
    }
    .title {
      color: #ffb06e;
      text-align: center;
      font-weight: bolder;
      margin-top: 40px;
      font-size: 52rpx;
      font-family: AlibabaPuHuiTiM;
      font-weight: 500;
      color: rgba(255, 137, 38, 1);
    }
    .sfztitle {
      font-size: 54rpx;
      font-family: Alibaba PuHuiTi;
      font-weight: 500;
      color: rgba(255, 137, 38, 1);
      text-align: center;
      margin-top: 20rpx;
    }
    .zanwusfztitle {
      font-size: 54rpx;
      font-family: Alibaba PuHuiTi;
      font-weight: 500;
      color: #cccccc;
      text-align: center;
      margin-top: 20rpx;
    }
    .yy {
      font-size: 12px;
    }
    .key {
      width: 100%;
      height: 80px;
      background: #4382ff;
      border-radius: 8px;
      font-size: 28px;
      color: white;
      margin-top: 40px;

      display: flex;
      align-items: center;
      justify-content: space-around;
      font-size: 80rpx;
      font-family: PingFang-SC-Bold;
      font-weight: bold;
      color: rgba(255, 255, 255, 1);
    }

    .key view {
    }
  }

  .footer {
    margin-top: 80rpx;
    display: flex;
    justify-content: center;
    align-items: center;

    .send {
      width: 620rpx;
      height: 85rpx;
    }
  }
}

.hubg {
  position: fixed;
  top: 0;
  height: 300rpx;
  z-index: -1;
  width: 100%;
}

.qiun-charts3 {
  width: 100%;
  height: 300upx;
  background-color: #ffffff;
  position: relative;
  display: flex;
  justify-content: center;
}

.charts3 {
  position: absolute;
  width: 300upx;
  height: 300upx;
  background-color: #ffffff;
}

.time {
  text-align: center;
  color: #4382ff;
}
.by {
  font-size: 32rpx;
  font-family: Alibaba PuHuiTi;
  font-weight: 400;
  color: rgba(59, 59, 59, 1);
  text-align: center;
  padding: 0 40upx;
}
.zanwuby {
  font-size: 32rpx;
  font-family: Alibaba PuHuiTi;
  font-weight: 400;
  color: #cccccc;
  text-align: center;
  padding: 0 40upx;
}
.dh {
  height: 23rpx;
  width: 23rpx;
  margin-left: 10rpx;
}
.tip {
  font-size: 24rpx;
  font-family: Alibaba PuHuiTi;
  font-weight: 400;
  color: rgba(255, 145, 37, 1);
  text-align: center;
  margin-top: 40rpx;
}
.zanwutip {
  font-size: 24rpx;
  font-family: Alibaba PuHuiTi;
  font-weight: 400;
  color: rgba(255, 145, 37, 1);
  text-align: center;
  margin-top: 40rpx;
  margin-bottom: 160rpx;
}
.english {
  font-size: 44rpx;
  font-family: Alibaba PuHuiTi;
  font-weight: 500;
  color: rgba(243, 244, 255, 1);
  text-align: center;
}
.getpassbtn {
  width: 100%;
  margin-top: 78upx;
}
.getpassbtn .btn {
  width: 655upx;
  height: 88upx;
  background: #4e6dd2;
  border-radius: 44upx;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36rpx;
  font-family: PingFang SC;
  font-weight: 500;
  color: #ffffff;
  margin-left: 30upx;
}
.getpassbtn2 {
  width: 100%;
  margin-top: 78upx;
}
.getpassbtn2 .btn {
  flex: 1;
  height: 88upx;
  background: #4e6dd2;
  border-radius: 44upx;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36rpx;
  font-family: PingFang SC;
  font-weight: 500;
  color: #ffffff;
  margin: 0 10px;
}
.passPop {
  height: 100vh;
  background: #fff;
}
.passPop .title {
  font-size: 36upx;
  font-weight: bold;
  color: #000;
  padding-top: 100upx;
  padding-bottom: 90upx;
  text-align: center;
}
.passPop .QRcodebox {
  height: 450upx;
  position: relative;
  text-align: center;
  margin-bottom: 66upx;
}
.passPop .QRcodebox .backborder {
  height: 450upx;
  width: 450upx;
}
.passPop .QRcodebox .QRcode {
  width: 100%;
  height: 450upx;
  position: absolute;
  left: 0upx;
  top: 0upx;
  text-align: center;
  line-height: 450upx;
}
.passPop .QRcodebox .QRcode image {
  width: 390upx;
  height: 390upx;
  margin-top: 30upx;
}

.passPop .tshi {
  font-size: 28upx;
  color: #ff3333;
  text-align: center;
}

.passPop .fresh {
  text-align: center;
  font-size: 32upx;
  color: #000;
  margin-top: 76upx;
}
.passPop .fresh text {
  display: inline-block;
  padding-left: 16upx;
  color: #ff3434;
}
.startimeBox {
  margin-left: 10%;
  margin-right: 10%;
  overflow: hidden;
  height: 100upx;
  display: flex;
  align-items: center;
  border-bottom: 1upx solid #ccc;
}
.startimeBox input {
  display: inline-block;

  margin-left: 20upx;
  width: 70%;
  height: 80upx;
  float: left;
}
.startimeBox .timetitle {
  display: inline-block;
  line-height: 80upx;
  float: left;
  font-weight: 600;
}
.startimeBox .picker {
  display: inline-block;
  width: 40upx;
  height: 40upx;
  float: right;
  margin-left: -20upx;
}
.startimeBox .picker image {
  width: 100%;
  height: 100% !important;
}
.passPoptwo .tshi {
  padding-bottom: 30upx;
}
.passPoptwo .tshi image {
  width: 24upx;
  height: 24upx;
  margin-right: 10upx;
}
.passPoptwo .title {
  padding-bottom: 30upx;
}
.gettwoPass {
  width: 90%;
  height: 88upx;
  line-height: 88upx;
  background: #4e6dd2;
  border-radius: 44upx;
  font-size: 36upx;
  color: #fff;
  margin-left: 5%;
  text-align: center;
  margin-top: 120upx;
}
.startendTime {
  font-size: 26upx;
  color: #ff3333;
  text-align: center;
  padding-top: 20upx;
}
.passshow {
  padding-top: 100upx;
}
.passshow .passnum {
  width: 90%;
  height: 124upx;
  line-height: 124upx;
  background: rgba(255, 145, 37, 1);
  border-radius: 8upx;
  font-size: 60upx;
  font-family: PingFang SC;
  font-weight: bold;
  color: #fff;
  margin-left: 5%;
  text-align: center;
  letter-spacing: 40upx;
}
.fixed {
  position: fixed;
  bottom: 40rpx;
  left: 50%;
  margin-left: -90rpx;
}
.bigbg {
  position: fixed;
  height: 100vh;
  width: 100%;

  background: #605e5e;
  top: 0;
  left: 0;
  display: none;
}
.passtitle {
  font-size: 36rpx;
  font-family: PingFang SC;
  font-weight: bold;
  color: #ffffff;
  text-align: center;
  margin-top: 182rpx;
  margin-bottom: 182rpx;
}
.passtip {
  font-size: 24rpx;
  font-family: Alibaba PuHuiTi;
  font-weight: 400;
  color: #ff3333;
  text-align: center;
}
.btnbox {
  display: flex;
  align-items: center;
}
.wusfz {
  display: flex;
  justify-content: space-around;
}
</style>
